<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>首页</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/main.css" />
    <link rel="stylesheet" type="text/css" href="../css/project.css" />
</head>
<body>
  <div id="header">
      <h3>首页</h3>
  </div>
  <div>
       <div id="banner"></div>
  	   <div class="nav_img">
  	   		<div onclick="openPage('myProject','project/myProject.html')" tapmode>
            <img src="../image/project_icon.png"/>
            <span>我的项目</span>
          </div>
  	   		<div onclick="openPage('myPower','power/myPower.html')" tapmode>
            <img src="../image/power_icon.png"/>
  	   		  <span>能力导航</span>
  	   		</div>
  	   		<div onclick="openPage('myProduct','product/myProduct.html')" tapmode>
            <img src="../image/product_icon.png"/>
  	   		  <span>作品地带</span>
  	   		</div>
          <div onclick="openPage('development','development/development.html')" tapmode>
            <img src="../image/develop_icon.png"/>
  	   		  <span>职业发展</span>
  	   		</div>
  	   </div>
       <div class="home">
         <div class="title"><img src="../image/hot.png"/>热门项目</div>
         <!-- <div class="list">
           <div class="project_company">
             <div class="left">
               <img src="../image/technology.png" class="company_logo"/>
             </div>
             <div class="left">
                 <div>广西犇云科技有限公司</div>
                 <div class="hot_tags"><span>软件开发</span><span>ios</span><span>广西科技大学</span></div>
              </div>
              <button class="btn btn-info">申请</button>
             </div>
              <div class="project_name">
                <span>项目名称：</span><span>大学了没</span><span>实验室名称：</span><span>广西科技大学</span>
              </div>
              <div class="project_detail">
                <span>地址：</span><span>306</span><span>招募岗位：</span><span>前端工程师</span><span>招募人数：</span><span>10</span><span>发布时间：</span><span>2017-09-08</span>
              </div>
         </div> -->
       </div>
  </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/main.js"></script>
<script type="text/javascript">
apiready=function(){
  //打开一个头部的frame
  api.openFrame({
      name: 'home_frame',
      url: 'home_frame.html',
      scrollEnabled:false,
      rect: {
          x: 0,
          y: 0,
          w: 'auto',
          h: '60'
      }
  });
  var banner=$("#banner")[0];
  $("#banner").css("height",api.winHeight / 4);
  var UIScrollPicture = api.require('UIScrollPicture');
  //获取首页轮播图
  var jwt=$api.getStorage('jwt');
  api.ajax({
    url: 'http://47.104.170.122/v1/portal/focuspic/get?type=app&token'+jwt,
    method: 'GET',
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Headers": "Authorization",
      "Content-Type" : 'application/json; charset=utf-8'
    }
  }, function(ret, err) {
    if(ret.code==0){
      var paths=[];
      for(var i=0;i<ret.data.length;i++){
        paths[i]="http://47.104.170.122/data/access/"+ret.data[i].filePath;
      }
      //var paths=ret.data.filepath;
      UIScrollPicture.open({
          rect: {
              x: 0,
              y: $api.offset(banner).t,
              w: api.winWidth,
              h: api.winHeight / 4
          },
          data: {
              paths: paths
          },
          styles: {
              indicator: {
                  align: 'center',
                  color: '#FFFFFF',
                  activeColor: '#bbb'
              }
          },
          placeholderImg: 'widget://image/banner1.jpg',
          contentMode: 'scaleToFill',
          fixed: false,
          fixedOn: 'frame1',
          loop: true
      }, function(ret, err) {
      });
    }else{
      toast("轮播图加载失败","bottom")
    }
  });

  var aid=$api.getStorage('aid');
  //判断是否为项目经理
  var flag=$api.getStorage('flag');
  //不分权限获取首页项目列表
  api.ajax({
      url: 'http://47.104.170.122/v1/portal/schoolEnterprise/student/app/positions?token='+jwt+'&pageNum=1&pageSize=100',
      method: 'GET',
      headers: {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Headers": "Authorization",
        "Content-Type" : 'application/json; charset=utf-8'
      }
    }, function(ret, err) {
      if(ret.code==0){
          var json=ret.data;
          var btn="";
          var status;
          $.each(json, function(commentIndex, comment){
            if(json[commentIndex].status==null){
              btn='<button class="btn btn-info">申请</button>';
              status='申请';
            }else{
              if(json[commentIndex].status==0){
                status='待审核'
              }
              else if(json[commentIndex].status==1){
                status='不通过'
              }
              else if(json[commentIndex].status==2){
                status='已通过'
              }
              else if(json[commentIndex].status==3){
                status='已完成'
              }
              btn='<button class="btn btn-info send">'+status+'</button>';
            }
            if(json[commentIndex].projectStatus==0){
              projectStatus='<span class="projectStatus" style="color:#fe9f59">待审核</span>'
            }else if(json[commentIndex].projectStatus==1){
              projectStatus='<span class="projectStatus" style="color:red">未通过</span>'
            }else if(json[commentIndex].projectStatus==2){
              projectStatus='<span class="projectStatus" style="color:#37acfe">进行中</span>'
            }else if(json[commentIndex].projectStatus==3){
              projectStatus='<span class="projectStatus" style="color:green">已完成</span>'
            }
            var templates='<div class="list"><div class="project_company" status="'+status+'"  positionId="'+json[commentIndex].id+'"><div class="left"><img src="'+json[commentIndex].pictureUrl+'" class="company_logo"/></div><div class="left"><div class="enterpriseName">'+json[commentIndex].enterpriseName+'</div><div class="hot_tags"><span>'+json[commentIndex].introduction+'</span></div></div>'+btn+'</div><div class="project_name"><span>项目名称：</span><span class="projectName">'+json[commentIndex].projectName+'</span><br><span>招募岗位：</span><span class="name">'+json[commentIndex].name+'</span><br><span>招募人数：</span><span class="total">'+json[commentIndex].total+'</span>&nbsp<span>当前人数：</span><span class="currentTotal">'
            +json[commentIndex].currentTotal+'</span>&nbsp<span>项目状态：</span>'+projectStatus+'</div></div>';
            $(".home").append(templates);
         });
      }else{
        toast("项目加载失败","bottom");
      }
    })
  //如果是项目经理
  // if(flag==3){
  //   var url='/api/paProject?aid='+aid;
  //   var functionRet=function(ret){
  //     var json=ret.list;
  //     var btn="";
  //     $.each(json, function(commentIndex, comment){
  //       if(json[commentIndex].isAttention==false){
  //         btn='<button class="btn btn-info">关注</button>';
  //       }else{
  //         btn='<button class="btn btn-info send">已关注</button>';
  //       }
  //       var templates='<div class="list"><div class="project_company" isAttention="'+json[commentIndex].isAttention+'"  projectId="'+json[commentIndex].projectId+'"><div class="left"><img src="'+json[commentIndex].logo+'" class="company_logo"/></div><div class="left"><div>'+json[commentIndex].businessName+'</div><div class="hot_tags"><span>'+json[commentIndex].keyWord+'</span></div></div>'+btn+'</div><div class="project_name"><span>项目名称：</span><span>'+json[commentIndex].projectName+'</span></div><div class="project_detail"><span>地址：</span><span>未知</span><span>发布时间：</span><span>'+timestampToTime(json[commentIndex].createTime)+'</span></div></div>';
  //       $(".home").append(templates);
  //    });
  //   }
  //   var functionErr=function(err){
  //       showProgress();
  //   }
  //   //加载项目列表
  //   get(url,functionRet,functionErr);
  // }else
  // //其他，0为技术人员，1为正在审核的技术人员，5为审核不通过的技术人员
  // {
  //   api.ajax({
  //     url: 'http://47.104.170.122/v1/portal/schoolEnterprise/student/projects?token='+jwt+'&pageNum=1&pageSize=100&majorId=1',
  //     method: 'GET',
  //     headers: {
  //       "Access-Control-Allow-Origin": "*",
  //       "Access-Control-Allow-Headers": "Authorization",
  //       "Content-Type" : 'application/json; charset=utf-8'
  //     }
  //   }, function(ret, err) {
  //     if(ret.code==0){
  //         var json=ret.data;
  //         var btn="";
  //         $.each(json, function(commentIndex, comment){
  //           if(json[commentIndex].isSendCV==false){
  //             btn='<button class="btn btn-info">申请</button>';
  //           }else{
  //             btn='<button class="btn btn-info send">已投递</button>';
  //           }
  //           var templates='<div class="list"><div class="project_company" isSendCV="'+json[commentIndex].isSendCV+'"  positionId="'+json[commentIndex].id+'"><div class="left"><img src="'+json[commentIndex].pictureUrl+'" class="company_logo"/></div><div class="left"><div>'+json[commentIndex].enterpriseName+'</div><div class="hot_tags"><span>'+json[commentIndex].keyWord+'</span></div></div>'+btn+'</div><div class="project_name"><span>项目名称：</span><span>'+json[commentIndex].name+'</span><span>实验室名称：</span><span>暂无</span></div><div class="project_detail"><span>地址：</span><span>未知</span><span>招募岗位：</span><span>'+json[commentIndex].positionName+'</span><br><span>招募人数：</span><span>'+json[commentIndex].number+'</span><br><span>发布时间：</span><span>'+
  //               timestampToTime(json[commentIndex].created)+'</span></div></div>';
  //           $(".home").append(templates);
  //        });
  //     }else{
  //       toast("项目加载失败","bottom");
  //     }
  //   })
  //   }
  }
//jquery
$(function(){
  var flag=$api.getStorage('flag');
  var aid=$api.getStorage('aid');
  //isLogin()
  //点击申请按钮,投递简历
  $(".home").on("click",".list .btn",function(e){
    if($(this).closest(".list").find(".projectStatus").html()!='已完成'){
      //判断是否为管理员
      if($api.getStorage('aid') == 1){
        api.toast({
            msg: '此功能仅提供用户使用'
        });
      }else{
        var button=$(this);
        if($(this).hasClass("send")){
          if(flag==3){
            toast("您已经关注过了","bottom");
          }else{
            toast("您已经投递过了","bottom");
          }
        }else{
            if(flag==3){
              // api.confirm({
              //     title: '提示',
              //     msg: '确定要关注企业吗',
              //     buttons: ['确定', '取消']
              // }, function(ret, err) {
              //     var index = ret.buttonIndex;
              //     var projectId=button.parent().attr("projectId");
              //     var data="";
              //     if(index==1){
              //       var url='/api/paProject/paAdminPaProjectAttention?aid='+aid+'&projectId='+projectId;
              //       var functionRet=function(ret){
              //         console.log(JSON.stringify(ret))
              //         api.alert({
              //             msg: '您已成功关注该项目，可在我的项目中查看到',
              //         });
              //         button.addClass("send");
              //         button.html("已关注");
              //       }
              //       var functionErr=function(err){
              //
              //       }
              //       //关注项目
              //       post(url,data,functionRet,functionErr);
              //     }
              // });
            }else{
              //先弹窗，写投递的自我介绍
              var dialogBox = api.require('dialogBox');
              dialogBox.input({
                  texts: {
                      title: '投递简历',
                      placeholder: '一句话介绍你自己',
                      leftBtnTitle: '取消',
                      rightBtnTitle: '确定'
                  },
                  styles: {
                      bg: '#fff',
                      corner: 4,
                      h: 200,
                      title: {
                          h: 45,
                          alignment: 'center',
                          size: 16,
                          color:'#838c94'
                      },
                      input: {
                          h: 32,
                          y:50,
                          marginT: 6,
                          textSize: 14,
                          textColor: '#000'
                      },
                      dividingLine: {
                          width: 0.5,
                          color: '#838c94'
                      },
                      left: {
                          bg: '#f3f3f3',
                          color: '#838c94',
                          size: 14
                      },
                      right: {
                          bg: '#37acfe',
                          color: '#fff',
                          size: 14
                      }
                  }
              }, function(ret) {
                  if (ret.eventType == 'left') {
                      var dialogBox = api.require('dialogBox');
                      dialogBox.close({
                          dialogName: 'input'
                      });
                  }
                  if (ret.eventType == 'right') {
                      //一句话介绍自己
                      var techIntr=ret.text;
                      var url='/student/apply/position';
                      var positionId=button.parent().attr("positionId");
                      var data={
                        "positionId": positionId,
                        "introduction": techIntr
                      };
                      var functionRet=function(ret){
                        if(ret.code==0){
                          button.addClass("send");
                          button.html("待审核");
                          api.alert({
                              msg: '您已成功投递该项目，等待企业回复',
                          });
                          var dialogBox = api.require('dialogBox');
                          dialogBox.close({
                              dialogName: 'input'
                          });
                        }else{
                          toast("投递失败，请重新投递","bottom");
                        }
                      }
                      var functionErr=function(err){
                      }
                      //ajax提交投递简历请求
                      if(techIntr==""){
                        api.alert({
                            msg: '请输入一句话介绍自己',
                        });
                      }else{
                        postNew(url,data,functionRet,functionErr);
                      }
                  }
              });
            }
        }
      }
    }else{
      toast("项目已完成，无法投递简历","middle");
    }
      //阻止事件冒泡
      e.stopPropagation();
  });
  //点击项目，打开项目详情页
  $(".home").on("click",".list",function(){
      //var projectId=$(this).find(".project_company").attr("projectId");
      var positionId=$(this).find(".project_company").attr("positionId");
      var status=$(this).find(".project_company").attr("status");
      var logo=$(this).find(".project_company .company_logo").attr("src");
      var enterpriseName=$(this).find(".enterpriseName").html();
      var projectName=$(this).find(".projectName").html();
      var name=$(this).find(".name").html();
      var total=$(this).find(".total").html();
      var currentTotal=$(this).find(".currentTotal").html();
      var projectStatus=$(this).find(".projectStatus").html();
      //打开一个新的页面，并且传递参数
      api.openWin({
          name: 'project_detail',
          url: 'project/project_detail.html',
          pageParam: {
              enterpriseName:enterpriseName,
              projectName:projectName,
              positionId: positionId,
              logo:logo,
              status:status,
              total:total,
              name:name,
              currentTotal:currentTotal,
              projectStatus:projectStatus
          }
      });
  })
})
</script>
</html>
